﻿
Partial Class WebForm_ManageTrainingCourse_QueryTrainingCourseGroup
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     
    End Sub

#Region "Delegate"

    '檢視
    Public Event SelectedIndexChanged(ByVal source As Object, ByVal e As EventArgs)

    Protected Sub GV_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GV.SelectedIndexChanged
        RaiseEvent SelectedIndexChanged(Me, New EventArgs)
    End Sub

    '編輯
    Public Event Editing(ByVal source As Object, ByVal e As EventArgs)

    Protected Sub GV_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GV.RowEditing
        GV.SelectedIndex = e.NewEditIndex
        RaiseEvent Editing(Me, New EventArgs)
        e.Cancel = True
    End Sub

    '刪除
    Public Event GVDelete(ByVal source As Object, ByVal e As EventArgs)

    Protected Sub lbtnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        RaiseEvent GVDelete(Me, New EventArgs)
    End Sub

#End Region

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click

        ObjectDataSource1.SelectParameters("UOrganizationID").DefaultValue = ddlUOrganizationID.SelectedValue
        ObjectDataSource1.SelectParameters("Annual").DefaultValue = Me.AnnualControl1.Anaual
        ObjectDataSource1.SelectParameters("TrainingGroupName").DefaultValue = Me.txtTrainingGroupName.Text.Replace("'", "''")
        GV.DataSourceID = ObjectDataSource1.ID
        GV.DataBind()

    End Sub

    Protected Sub ddlUOrganizationID_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlUOrganizationID.DataBound
        Dim ddlUOrganizationID As DropDownList = TryCast(sender, DropDownList)

        If ddlUOrganizationID.Items.Count > 1 Then

            ddlUOrganizationID.Items.Insert(0, New ListItem(Me.GetLocalResourceObject("PleaseSelect"), String.Empty))

        End If
    End Sub

    Protected Sub GV_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GV.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            If TypeOf DataBinder.Eval(e.Row.DataItem, "HaveAccess") Is DBNull Then
                TryCast(e.Row.FindControl("lbtnDelete"), LinkButton).Visible = False
                TryCast(e.Row.FindControl("mvForm"), MultiView).SetActiveView(TryCast(e.Row.FindControl("vwSelect"), View))
            ElseIf DataBinder.Eval(e.Row.DataItem, "HaveAccess") = "Y" Then
                'TryCast(e.Row.FindControl("lbtnDelete"), LinkButton).Visible = True
                TryCast(e.Row.FindControl("mvForm"), MultiView).SetActiveView(TryCast(e.Row.FindControl("vwEdit"), View))
            Else
                TryCast(e.Row.FindControl("lbtnDelete"), LinkButton).Visible = False
                TryCast(e.Row.FindControl("mvForm"), MultiView).SetActiveView(TryCast(e.Row.FindControl("vwSelect"), View))
            End If
        End If
    End Sub


    Protected Sub ddlUOrganizationID_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlUOrganizationID.Load
        If Not IsPostBack Then
            Me.ddlUOrganizationID.DataTextField = "OrganizationName"
            Me.ddlUOrganizationID.DataValueField = "UOrganizationID"
            Me.ddlUOrganizationID.DataSource = MyObj.GetAllDDLOrganizationData()
            Me.ddlUOrganizationID.DataBind()

            Me.ddlUOrganizationID.Items.Insert(0, MyObj.GetDDLPleaseChooseItem())
        End If
    End Sub

    Protected Sub AnnualControl1_Loaded(ByVal source As Object, ByVal e As System.EventArgs) Handles AnnualControl1.Loaded
        ObjectDataSource1.SelectParameters("Annual").DefaultValue = Me.AnnualControl1.Anaual
        GV.DataSourceID = ObjectDataSource1.ID
        GV.DataBind()
    End Sub
End Class

Partial Class WebForm_ManageTrainingCourse_QueryTrainingCourseGroup

    Public Sub InitData()

        'GV.DataSourceID = ObjectDataSource1.ID
        'GV.DataBind()

    End Sub

#Region "Property"

    Public ReadOnly Property SelectedID() As String
        Get
            If Me.GV.SelectedRow Is Nothing Then
                Return 0
            Else
                Return Me.GV.DataKeys(Me.GV.SelectedIndex).Value
            End If

        End Get
    End Property

#End Region

End Class
